package com.briup.bookstore.common.model.vo;

import com.briup.bookstore.common.model.entity.Book;
import com.briup.bookstore.common.model.entity.Order;
import com.briup.bookstore.common.model.entity.OrderItem;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

/**
 * @author YuYan
 * @date 2023-12-27 20:54:12
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrderItemVO {
    private Integer id;
    private String orderId;
    private Integer num;

    private String name;
    private Double price;
    private String cover;
    private Double totalPrice;

    public static OrderItemVO toVO(OrderItem orderItem) {
        return OrderItemVO.builder()
                .id(orderItem.getId())
                .orderId(orderItem.getOrderId())
                .num(orderItem.getNum())
                .name(orderItem.getBook().getName())
                .cover(orderItem.getBook().getCover())
                .price(orderItem.getBook().getPrice())
                .totalPrice(orderItem.getBook().getPrice() * orderItem.getNum())
                .build();
    }
}
